package com.mvp.lt.airlineview.utils;

import android.graphics.Color;
import android.view.View;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.mvp.lt.airlineview.App;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Android Studio.
 * User: Administrator
 * Date: 2019/4/26 0026
 * Time: 下午 15:15
 */
public class TextCodeUtils {
    private String startAge;
    private String endAge;
    private OptionsPickerView mSexOptions, mAgeOptions;
    private List<String> ageList = new ArrayList<>();
    private List<List<String>> mOptionsAgeItems = new ArrayList<>();

    /**
     * 年龄选择器构建
     */
    private void initAgeOptionsPicker() {
        mAgeOptions = new OptionsPickerBuilder(App.getContext(), new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                if (ageList.get(options1).equals("不限")) {
                    startAge = "0岁";
                } else {
                    startAge = ageList.get(options1);
                }
                if (mOptionsAgeItems.get(options1).get(options2).equals("不限")) {
                    endAge = "100岁";
                } else {
                    endAge = mOptionsAgeItems.get(options1).get(options2);
                }
                LogUtil.d("年龄选择", startAge + ":::" + endAge);

            }
        }).setTitleText("请选择")
                .setOutSideCancelable(false)
                .setTitleColor(Color.BLACK)
                .build();
        mAgeOptions.setPicker(ageList, mOptionsAgeItems);
        mAgeOptions.setSelectOptions(0, 0);

    }

    public void buildeAgeList() {
        //150-18 + 不限
        String[] ages = new String[84];
        ages[0] = "不限";
        for (int i = 1; i <= 83; i++) {
            ages[i] = 17 + i + "岁";
        }
        //利用Arrays.asList转化为集合，注意该方法转化的集合不能够记性add或remove等操作
        ageList = Arrays.asList(ages);
        mOptionsAgeItems = new ArrayList<>();
        //由于需要将ageList作为第一个参数list传入，
        // 所以需要一个临时list把ageList的数据存起来转入第二个参数中
        List<String> listTemp = new ArrayList<>();
        listTemp.clear();
        for (int j = 0; j < ageList.size(); j++) {
            //将ageList中的数据全部拷贝一份到listTemp里面
            listTemp.add(ageList.get(j));
        }
        for (int k = 0; k < 84; k++) {
            //注意：这里必须要在for循环里面new，
            //否则mOptionsAgeItems集合里面每个子集合都是一样的
            //这里涉及到引用对象地址的唯一性问题，String也是引用对象
            List<String> sencondAgeList = new ArrayList<>();
            //以下作用就是构建第二级数据的原理，非常简单
            if (k > 0) {
                listTemp.remove(0);
            }
            if (k != 0) {
                sencondAgeList.add(ages[0]);
            }
            sencondAgeList.addAll(listTemp);

            mOptionsAgeItems.add(sencondAgeList);
        }
    }
}
